package com.ken.quartz.timer;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimerTask;

/**
 * Created by renchongyu on 2018/11/25.
 */
public class MyTimerTask extends TimerTask {

    private String name;

    private Integer count = 0;

    public MyTimerTask(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        if(count>3){
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("MyTimerTask time="+sdf.format(calendar.getTime()));
            System.out.println("MyTimerTask: "+name);
            count++;
        }else {
            cancel();//取消任务
        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
